package com.litong.litongjiaoyu.service.impl;

import com.litong.litongjiaoyu.dao.LeaveDao;
import com.litong.litongjiaoyu.entity.StudentLeave;
import com.litong.litongjiaoyu.entity.StudentUserinfo;
import com.litong.litongjiaoyu.service.LeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @ClassName LeaveServiceImpl
 * @Description 学生请假系统服务层具体实现
 * @Author jingz
 * @Date 2019/11/25 10:37
 * @Version 1.0
 **/

@Service
public class LeaveServiceImpl implements LeaveService {

    @Autowired
    private LeaveDao leaveDao;

    /**
     * 根据班级获取全部学生请假信息
     *
     * @param campus 学生班级
     * @return
     */
    @Override
    public List<StudentLeave> query(String campus) {
        List<StudentLeave> leaves = leaveDao.query(campus);
        return leaves;
    }

    /**
     * 获取在请假期间且请假状态为已确认的学生
     * @param classname 班级
     * @param campus 校区
     * @return
     */
    @Override
    public List<StudentLeave> getLeaveStudent (String classname, String campus) {
        return leaveDao.getLeaveStudent(classname, campus);
    }
    
    /**
     * 获取指定人请假记录
     * @param phone 手机号
     * @return
     */
    @Override
    public List<StudentLeave> getYourselfLeave(String phone) {
        return leaveDao.getYourselfLeave(phone);
    }

    /**
     * 获取未请假的学生信息
     *
     * @param className
     * @param campus
     * @return
     */
    @Override
    public List<StudentUserinfo> getStudentList(String className, String campus) {
        return leaveDao.getStudentList(className, campus);
    }

    /**
     * 审批
     *
     * @param review
     * @return
     */
    @Transactional
    @Override
    public int review(Map<Long, String> review) {
        return leaveDao.review(review);

    }


    /**
     * 添加请假申请记录
     *
     * @param studentLeave
     * @return
     */
    @Transactional
    @Override
    public int application(StudentLeave studentLeave) {
        return leaveDao.application(studentLeave);
    }

    /**
     * 清空数据表
     *
     * @return
     */
    @Transactional
    @Override
    public int removeAll() {
        return leaveDao.removeAll();
    }

    /**
     * 添加信息
     * @param studentLeave 需要更新的请假信息
     * @return 更新成功个数
     */
    @Override
    public int updateStatus(StudentLeave studentLeave) {
        return leaveDao.updateStatus(studentLeave);
    }
}
